window.onload = function (ev) {
    var lis = document.getElementsByTagName("li");
    for (var i = 0; i < lis.length; i++) {
        bindEvents(lis[i])
    }

    //获取选择类别
    document.getElementById("button").onclick = function (ev1) {
        var type = null;
        var types = document.getElementsByName("type");
        for (var i = 0; i < types.length; i++) {
            if (types[i].checked) {
                type = types[i].value;
                break;
            }
        }
        if (type == null) {
            alert("请选择类别");
            return;
        }
        console.info(type);


        //获取输入内容
        var input = document.getElementsByName("name")[0].value;
        if (input.length == 0) {
            alert("请输入内容");
            return;
        }


        //根据类别添加内容
        var newLi = document.createElement("li");
        var text = document.createTextNode(input);
        newLi.appendChild(text);

        var ul = document.getElementById(type);
        ul.appendChild(newLi);

        document.getElementsByName("name")[0].value = '';
        bindEvents(newLi)
    }

    function bindEvents(node) {
        node.onclick = function () {
            alert(this.firstChild.nodeValue)
        }
    }
}

